
#include <BOpenGL>

#include "OpenGLWidget.h"

void OpenGLWidget::updateEvent(const BEvent& event)
{
	_currentAngle += 1;
	this->fresh();
}

void OpenGLWidget::paintEvent(const BEvent& event)
{
	BRect crect = this->centerRect();

	BPoint p0 = crect.leftTop();
	BPoint p1 = crect.leftBottom();
	BPoint p2 = crect.rightBottom();
	BPoint p3 = crect.rightTop();

	glColor3f(1.0f, 0.0f, 0.0f);

	glBegin(GL_QUADS);
	glVertex3i(p0.x(), p0.y(), 0);
	glVertex3i(p1.x(), p1.y(), 0);
	glVertex3i(p2.x(), p2.y(), 0);
	glVertex3i(p3.x(), p3.y(), 0);
	glEnd();

	float radius = bMin(crect.width(), crect.height()) / 4.0f;

	float angle = bDTR(_currentAngle);
	BPointf va = crect.center() + BPointf(cos(angle) * radius, sin(angle) * radius);
	angle += bDTR(120);
	BPointf vb = crect.center() + BPointf(cos(angle) * radius, sin(angle) * radius);
	angle += bDTR(120);
	BPointf vc = crect.center() + BPointf(cos(angle) * radius, sin(angle) * radius);

	glColor3f(0.0f, 1.0f, 0.0f);
	glBegin(GL_TRIANGLES);
	glVertex3f(va.x(), va.y(), 0);
	glVertex3f(vb.x(), vb.y(), 0);
	glVertex3f(vc.x(), vc.y(), 0);
	glEnd();

}

